/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Padre.java
 *
 * Created on 07-dic-2013, 13:30:44
 */
package sistemataller;

import maestros.*;
import core.*;
import java.awt.*;
import javax.swing.*;

/**
 *
 * @author Luis García
 */
public class Padre extends javax.swing.JFrame {

    JDesktopPane desktop;
    private String condiciones, tbls;
    private Object[][] valores;
    private Query cmd;
    private Conexion conn;
    int idrol;
    String idUsuario;

    public Padre(int idrol) {

        this.idrol = idrol;


        initComponents();
        Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
        int height = pantalla.height;
        int width = pantalla.width;
        setSize(width, height);
        setLocationRelativeTo(null);


        setTitle(getNomRolUsuario());
        habilitaMenus();


        String imagenfondo="admin.jpg";
        if(idrol!=1){
            imagenfondo=null;
        }
        desktop = new Escritorio();
        desktop.setBorder(new ImagenFondo(imagenfondo));
        add(desktop);
        desktop.setVisible(true);


    }

    private void habilitaMenus() {

        menuMaestros.setEnabled(false);
        menuUsuarios.setEnabled(false);
        menuOrdenes.setEnabled(false);
        menuMantenciones.setEnabled(false);
        menuFichas.setEnabled(false);
        switch (idrol) {
            case 1:

                menuMaestros.setEnabled(true);
                menuUsuarios.setEnabled(true);
                menuOrdenes.setEnabled(true);
                menuMantenciones.setEnabled(true);
                menuFichas.setEnabled(true);
                break;
            case 2:
                menuOrdenes.setEnabled(true);
                menuMaestros.setEnabled(true);
                break;
            case 3:
                menuFichas.setEnabled(true);
                break;
            case 4:
                menuMantenciones.setEnabled(true);
                break;
        }


    }

    private String getNomRolUsuario() {
        conn = new Conexion();
        cmd = new Query(conn);
        condiciones = " 1 ";
        String[] campos = {"t1.nombre", "t2.nombre", "t1.id_usuario"};
        valores = cmd.leeRegistros(campos, "t1.id_usuario=" + idrol + " and t1.id_rol=t2.id_rol", "tbl_usuario t1, tbl_rol t2");
        conn.desconectar();

        idUsuario = valores[0][2].toString();

        return valores[0][0].toString() + " ::: " + valores[0][1].toString();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        jPopupMenu2 = new javax.swing.JPopupMenu();
        jButton1 = new javax.swing.JButton();
        menuPrincipal = new javax.swing.JMenuBar();
        menuAgenteSmith = new javax.swing.JMenu();
        itemAgenteSmith_acerca = new javax.swing.JMenuItem();
        menuApariencia = new javax.swing.JMenu();
        subitem_cambiarfondo = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        itemAgenteSmith_salir = new javax.swing.JMenuItem();
        menuMaestros = new javax.swing.JMenu();
        subitem_tiposvehiculo = new javax.swing.JMenu();
        subitem_marcas = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        subitem_modelos = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem4 = new javax.swing.JMenuItem();
        menuOrdenes = new javax.swing.JMenu();
        menuFichas = new javax.swing.JMenu();
        menuMantenciones = new javax.swing.JMenu();
        menuUsuarios = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("jButton1");

        menuAgenteSmith.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/agente.png"))); // NOI18N
        menuAgenteSmith.setText("AgenteSmith");

        itemAgenteSmith_acerca.setText("Acerca de AgenteSmith");
        itemAgenteSmith_acerca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemAgenteSmith_acercaActionPerformed(evt);
            }
        });
        menuAgenteSmith.add(itemAgenteSmith_acerca);

        menuApariencia.setText("Apariencia");

        subitem_cambiarfondo.setText("Cambiar Fondo");

        jMenuItem1.setText("Default");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        subitem_cambiarfondo.add(jMenuItem1);

        jMenuItem3.setText("Calle");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        subitem_cambiarfondo.add(jMenuItem3);

        jMenuItem5.setText("Curva");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        subitem_cambiarfondo.add(jMenuItem5);

        jMenuItem6.setText("Matrix");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        subitem_cambiarfondo.add(jMenuItem6);

        menuApariencia.add(subitem_cambiarfondo);

        menuAgenteSmith.add(menuApariencia);

        jMenuItem7.setText("Cerrar sesion");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        menuAgenteSmith.add(jMenuItem7);

        itemAgenteSmith_salir.setText("Salir");
        itemAgenteSmith_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemAgenteSmith_salirActionPerformed(evt);
            }
        });
        menuAgenteSmith.add(itemAgenteSmith_salir);

        menuPrincipal.add(menuAgenteSmith);

        menuMaestros.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/gear2.png"))); // NOI18N
        menuMaestros.setText("Maestros");

        subitem_tiposvehiculo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/rueda.png"))); // NOI18N
        subitem_tiposvehiculo.setText("Vehiculos");

        subitem_marcas.setText("Tipos");
        subitem_marcas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subitem_marcasActionPerformed(evt);
            }
        });
        subitem_tiposvehiculo.add(subitem_marcas);

        jMenuItem2.setText("Marcas");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        subitem_tiposvehiculo.add(jMenuItem2);

        subitem_modelos.setText("Modelos");
        subitem_modelos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subitem_modelosActionPerformed(evt);
            }
        });
        subitem_tiposvehiculo.add(subitem_modelos);

        menuMaestros.add(subitem_tiposvehiculo);
        menuMaestros.add(jSeparator1);

        jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistemataller/volante.png"))); // NOI18N
        jMenuItem4.setText("Repuestos");
        jMenuItem4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jMenuItem4MousePressed(evt);
            }
        });
        menuMaestros.add(jMenuItem4);

        menuPrincipal.add(menuMaestros);

        menuOrdenes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/blank.png"))); // NOI18N
        menuOrdenes.setText("Ingreso Vehiculo");
        menuOrdenes.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/images/blank.png"))); // NOI18N
        menuOrdenes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                menuOrdenesMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                menuOrdenesMouseReleased(evt);
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                menuOrdenesMouseClicked(evt);
            }
        });
        menuOrdenes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuOrdenesActionPerformed(evt);
            }
        });
        menuOrdenes.addMenuKeyListener(new javax.swing.event.MenuKeyListener() {
            public void menuKeyPressed(javax.swing.event.MenuKeyEvent evt) {
                menuOrdenesMenuKeyPressed(evt);
            }
            public void menuKeyReleased(javax.swing.event.MenuKeyEvent evt) {
            }
            public void menuKeyTyped(javax.swing.event.MenuKeyEvent evt) {
            }
        });
        menuPrincipal.add(menuOrdenes);

        menuFichas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/cars.png"))); // NOI18N
        menuFichas.setText("Fichas");
        menuFichas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                menuFichasMouseReleased(evt);
            }
        });
        menuFichas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuFichasActionPerformed(evt);
            }
        });
        menuFichas.addMenuKeyListener(new javax.swing.event.MenuKeyListener() {
            public void menuKeyPressed(javax.swing.event.MenuKeyEvent evt) {
            }
            public void menuKeyReleased(javax.swing.event.MenuKeyEvent evt) {
                menuFichasMenuKeyReleased(evt);
            }
            public void menuKeyTyped(javax.swing.event.MenuKeyEvent evt) {
            }
        });
        menuPrincipal.add(menuFichas);

        menuMantenciones.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/tools2.png"))); // NOI18N
        menuMantenciones.setText("Mantenciones");
        menuPrincipal.add(menuMantenciones);

        menuUsuarios.setText("Usuarios");
        menuUsuarios.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/images/tools2.png"))); // NOI18N
        menuPrincipal.add(menuUsuarios);

        setJMenuBar(menuPrincipal);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 829, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 237, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void subitem_marcasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subitem_marcasActionPerformed
        // TODO add your handling code here:
        TipoVehiculo tipovehiculo = new TipoVehiculo();




        int x = (desktop.getWidth() / 2) - tipovehiculo.getWidth() / 2;
        int y = (desktop.getHeight() / 2) - tipovehiculo.getHeight() / 2;

        if (tipovehiculo.isShowing()) {

            tipovehiculo.setLocation(x, y);
        } else {

            desktop.add(tipovehiculo);
            tipovehiculo.setLocation(x, y);
            tipovehiculo.show();

        }



    }//GEN-LAST:event_subitem_marcasActionPerformed

    private void itemAgenteSmith_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemAgenteSmith_salirActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_itemAgenteSmith_salirActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
        Marcas marcas = new Marcas();




        int x = (desktop.getWidth() / 2) - marcas.getWidth() / 2;
        int y = (desktop.getHeight() / 2) - marcas.getHeight() / 2;

        if (marcas.isShowing()) {

            marcas.setLocation(x, y);
        } else {

            desktop.add(marcas);
            marcas.setLocation(x, y);
            marcas.show();

        }
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void subitem_modelosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subitem_modelosActionPerformed
        Modelos modelos = new Modelos();




        int x = (desktop.getWidth() / 2) - modelos.getWidth() / 2;
        int y = (desktop.getHeight() / 2) - modelos.getHeight() / 2;

        if (modelos.isShowing()) {

            modelos.setLocation(x, y);
        } else {

            desktop.add(modelos);
            modelos.setLocation(x, y);
            modelos.show();

        }
    }//GEN-LAST:event_subitem_modelosActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        desktop.setBorder(new ImagenFondo(null));
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        desktop.setBorder(new ImagenFondo("fondo2.jpg"));
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        // TODO add your handling code here:
        desktop.setBorder(new ImagenFondo("fondo4.jpg"));
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        // TODO add your handling code here:
        desktop.setBorder(new ImagenFondo("fondo3.jpg"));
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void menuOrdenesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuOrdenesActionPerformed
    }//GEN-LAST:event_menuOrdenesActionPerformed

    private void menuFichasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFichasActionPerformed
        
    }//GEN-LAST:event_menuFichasActionPerformed

    private void menuOrdenesMenuKeyPressed(javax.swing.event.MenuKeyEvent evt) {//GEN-FIRST:event_menuOrdenesMenuKeyPressed
        // TODO add your handling code here:
        System.out.println("-- yo -->");
    }//GEN-LAST:event_menuOrdenesMenuKeyPressed

    private void menuOrdenesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_menuOrdenesMouseClicked
    }//GEN-LAST:event_menuOrdenesMouseClicked

    private void menuOrdenesMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_menuOrdenesMouseReleased
    }//GEN-LAST:event_menuOrdenesMouseReleased

    private void menuOrdenesMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_menuOrdenesMousePressed
        Ingreso ingreso = new Ingreso(idUsuario);

        int x = (desktop.getWidth() / 2) - ingreso.getWidth() / 2;
        int y = (desktop.getHeight() / 4) - ingreso.getHeight() / 4;

        if (ingreso.isShowing()) {

            ingreso.setLocation(x, y);
        } else {



            desktop.add(ingreso);
            ingreso.setLocation(x, y);
            ingreso.show();

        }
    }//GEN-LAST:event_menuOrdenesMousePressed

    private void jMenuItem4MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem4MousePressed
        Repuestos repuesto = new Repuestos();

        int x = (desktop.getWidth() / 2) - repuesto.getWidth() / 2;
        int y = (desktop.getHeight() / 4) - repuesto.getHeight() / 4;

        if (repuesto.isShowing()) {

            repuesto.setLocation(x, y);
        } else {



            desktop.add(repuesto);
            repuesto.setLocation(x, y);
            repuesto.show();

        }
    }//GEN-LAST:event_jMenuItem4MousePressed

    private void itemAgenteSmith_acercaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemAgenteSmith_acercaActionPerformed
        Creditos credito = new Creditos();
        int x = (desktop.getWidth() / 2) - credito.getWidth() / 2;
        int y = (desktop.getHeight() / 4) - credito.getHeight() / 4;

        if (credito.isShowing()) {

            credito.setLocation(x, y);
        } else {



            desktop.add(credito);
            credito.setLocation(x, y);
            credito.show();

        }
    }//GEN-LAST:event_itemAgenteSmith_acercaActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        // TODO add your handling code here:

      Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
        int height = 230;
        int width = pantalla.width / 3;

        Login login = new Login();
        login.setSize(width, height);
        login.setLocationRelativeTo(null);


        login.setVisible(true);
        dispose();

    }//GEN-LAST:event_jMenuItem7ActionPerformed
 
    private void menuFichasMenuKeyReleased(javax.swing.event.MenuKeyEvent evt) {//GEN-FIRST:event_menuFichasMenuKeyReleased
       
    }//GEN-LAST:event_menuFichasMenuKeyReleased

    private void menuFichasMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_menuFichasMouseReleased
       Fichas ficha=new Fichas();
        int x = (desktop.getWidth() / 2) - ficha.getWidth() / 2;
        int y = (desktop.getHeight() / 2) - ficha.getHeight() / 2;

        if (ficha.isShowing()) {

            ficha.setLocation(x, y);
        } else {

            desktop.add(ficha);
            ficha.setLocation(x, y);
            ficha.show();

        }
    }//GEN-LAST:event_menuFichasMouseReleased

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Padre(1).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem itemAgenteSmith_acerca;
    private javax.swing.JMenuItem itemAgenteSmith_salir;
    private javax.swing.JButton jButton1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JPopupMenu jPopupMenu2;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JMenu menuAgenteSmith;
    private javax.swing.JMenu menuApariencia;
    private javax.swing.JMenu menuFichas;
    private javax.swing.JMenu menuMaestros;
    private javax.swing.JMenu menuMantenciones;
    private javax.swing.JMenu menuOrdenes;
    private javax.swing.JMenuBar menuPrincipal;
    private javax.swing.JMenu menuUsuarios;
    private javax.swing.JMenu subitem_cambiarfondo;
    private javax.swing.JMenuItem subitem_marcas;
    private javax.swing.JMenuItem subitem_modelos;
    private javax.swing.JMenu subitem_tiposvehiculo;
    // End of variables declaration//GEN-END:variables
}
